package view;

import java.awt.Color;

import javax.swing.JPanel;

import model.Model;
import util.Direction;
import util.MyPosition;

public abstract class ModelView extends JPanel {
    protected Color color;
    protected MyPosition position;
    protected MyPosition oldPosition;
    protected Direction dirStatic; // 移动状态
    protected Direction faceDir; // 面朝方向
    protected long gameid;

    public ModelView(MyPosition myPosition, Model model) {
        position = new MyPosition(myPosition);
        color = getCampColor(model.getCamp());
        oldPosition = position;
        faceDir = getFaceDir(model.getCamp());
        gameid = model.getGameid();
    }

    private Direction getFaceDir(int camp) {
        if (camp == Model.RED_CAMP)
            return Direction.U;
        else
            return Direction.D;
    }

    private Direction getFaceDir(Direction direction) {
        if (direction == Direction.STOP)
            return this.faceDir;
        return direction;
    }

    private Color getCampColor(int camp) {
        if (camp == Model.RED_CAMP)
            return Color.red;
        else
            return Color.blue;
    }

    public abstract void stay();

    // set&get
    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
        repaint();
    }

    public MyPosition getPosition() {
        return position;
    }

    public abstract void setPosition(MyPosition position);

    public void setDir(Direction direction) {
        dirStatic = direction;
        faceDir = getFaceDir(direction);
        repaint();
    }

    public Direction getDir() {
        return dirStatic;
    }

    public Direction getFace(){
        return faceDir;
    }

    public long getGameid() {
        return gameid;
    }
}
